﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class TaoBaoApi_TB_Trades : System.Web.UI.Page
{
    private string Key
    {
        get
        {
            if (Request.QueryString["key"] == null || Request.QueryString["key"].ToString().Length == 0)
                return null;
            return Request.QueryString["key"].ToString();
        }
    }
    TBCommon myT = new TBCommon();
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Key == null)
            {
                AspNetPager1.PageSize = ConfigurationManager.AppSettings["RowCountPerPage"].ToString().Length > 0 ?
                        Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString()) : 10;
                SearchControl1.InitParam("TB_XSJRD", "MID", "DJBH", "xsjrd1", "rptTB_XSJRD", "AspNetPager1");
                Bind();
                div_Info.Visible = false;
                
            }
            else
            {                
                myT.BindTBShop(ddlShop);
                BindOne();
            }           
        }
    }
    void Bind()
    {
        int pageCount = 0;
        int rowCount = 0;
        List<Model.TaoBao.TB_XSJRD> properties = new BLL.TaoBao.TB_XSJRD().GetList(this.AspNetPager1.PageSize,
            this.AspNetPager1.CurrentPageIndex, "MID", false, "", out pageCount, out rowCount);
        xsjrd1.Bind(properties);
        this.AspNetPager1.RecordCount = rowCount;
    }
    void BindOne()
    {
        List<Model.TaoBao.TB_XSJRD> ps = new List<Model.TaoBao.TB_XSJRD>();
        Model.TaoBao.TB_XSJRD p = null;
        int MID = 0;
        try
        {
            MID = Convert.ToInt32(Key);
            p = new BLL.TaoBao.TB_XSJRD().GetModel(MID);
            ps.Add(p);
            xsjrd1.Bind(ps);
            this.AspNetPager1.RecordCount = 1;
        }
        catch {
            Response.Redirect("tb_trades.aspx");
            return;
        }
        txtTid.Text = p.TB_NO;
        txtCreated.Text = p.RQ.ToShortDateString();
        txtMJ.Text = p.MJ;
        txtNum.Text = p.SL.ToString();
        txtJine.Text = p.JE.ToString();
        txtBZ.Text = p.BZ;
        txtDJBH.Text = p.MID.ToString();
        ddlShop.Text = new BLL.TaoBao.TB_SHANGDIAN().GetModel(p.TD_ID).PWD;

        //订单附加信息
        //交易信息
        new TBCommon().BindTBTradeStatus(ddlJYStatus);
        new TBCommon().BindTBTradeType(ddlJYType);
        Model.TaoBao.TB_XSJRD_JY jy = new TBCommon().GetJYModelbyPID(MID);
        if (jy != null)
        {
            txtZFB.Text = jy.alipay_no;            
            ddlJYStatus.SelectedValue = jy.status.ToUpper();
            txtSHJine.Text = jy.payment;
            ddlJYType.SelectedValue = jy.type;           
            if (jy.seller_rate == 1)
                chkMJPJ.Checked = true;
            if (jy.buyer_rate == 1)
                chkMJPJ2.Checked = true;
            txtJYCreated.Text = jy.created.ToString();
        }
        //买家信息
        new TBCommon().BindTBSex(ddlSex);
        Model.TaoBao.TB_XSJRD_MJ MJ = new TBCommon().GetMJModelbyPID(MID);
        if (MJ != null)
        {
            txtMJNC.Text = MJ.MJ;
            ddlSex.SelectedValue = MJ.SEX;
            txtMJReg.Text = MJ.ZCSJ.ToString();
            txtMJVisit.Text = MJ.ZJDL.ToString();
        }
        //物流
        new TBCommon().BindTBWLType(ddlWLType);
        new TBCommon().BindTBWLStatus(ddl4KDStatus);
        new TBCommon().BindTBWLPay(ddl4freight_payer);

        //商品**
        List<Model.TaoBao.TB_XSJRD_SP> spList = new TBCommon().GetTb_Xsjrd_SpListbytid(p.TB_NO);
        gvBaobei.DataSource = spList;
        
        gvBaobei.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        int pageCount = 0;
        int rowCount = 0;
        if (SearchControl1.IsSearchResult)
        {
            Repeater rpt = (Repeater)xsjrd1.FindControl("rptTB_XSJRD");
            if (rpt != null)
            {
                string strSql;
                SearchControl1.BindParentPageControl(rpt, AspNetPager1, SearchControl1.DataTableName, SearchControl1.PrimaryKeyColumnName,
                    SearchControl1.StrCondition, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out rowCount, out strSql);
            }
        }
        else
        {
            List<Model.TaoBao.TB_XSJRD> colors = new BLL.TaoBao.TB_XSJRD().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex,
                "MID", false, "", out pageCount, out rowCount);
            xsjrd1.Bind(colors); 
        }
    }
    protected void btnDown_Click(object sender, EventArgs e)
    {
        Response.Redirect("tb_downtrade.aspx");
    }
    /// <summary>
    /// 显示多个Tab
    /// </summary>
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        multiView1.ActiveViewIndex = Convert.ToInt32(Menu1.SelectedValue);
    }    
}
